Market Price

What we have to do here is create market simulation program.

Question: how to make highest net benefit?

Example Data

[90, 200]

Example Data

[90, 200]

Buy at 90

Sell at 200

Example Data

[90, 200]

Buy at 90

Sell at 200

Net Value 110

Example Data

[200, 90]

Sell at 200

Buy at 90

Net Value is 110

We should ban toyota!!!

Example Data

[90, 100, 200, 40]

Based on above data, there are several scenarios we can think.

Example Data

[90, 100, 200, 40]

First market price is 90

Example Data

[90, 100, 200, 40]

Then lets buy the stock.

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

Now market price is 100.

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

But since we know there is more higher value is coming, we skip it.

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

Now market price is 200.

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

Lets sell it.

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

You made 110 net value.

1qty at 90

Buy Sell

200 - 90 = 110

Example Data

[90, 100, 200, 40]

At market price 40, we dont do anything.

1qty at 90

Buy Sell

200 - 90 = 110

Example Data

[90, 100, 200, 40]

Or,,,

1qty at 90

Buy Sell

200 - 90 = 110

Example Data

[90, 100, 200, 40]

Or,,,you can buy 90... and ...

1qty at 90

Buy Sell

Example Data

[90, 100, 200, 40]

Sell at 100

1qty at 90

Buy Sell

100 - 90 = 10

Example Data

[90, 100, 200, 40]

And sell at 200

1qty at 200

Buy Sell

Net value 10

Example Data

[90, 100, 200, 40]

And buy at 40

1qty at 40

Buy Sell

Net value 10

200 - 40 = 160

Example Data

[90, 100, 200, 40]

Total is 170...

1qty at 40

Buy Sell

Net value 10

200 - 40 = 160

160 + 10 = 170

Example Data

[90, 100, 200, 40]

In this case, 170 are bigger. So then this answer is 170. 

1qty at 40

Buy Sell

Net value 10

200 - 40 = 160

160 + 10 = 170

Condition

Always 1qty at a time.

Condition

Always 1qty at a time.

You have unlimited money.

Condition

Always 1qty at a time.

You have unlimited money.

One Time One Action

(Buy, Sell or stay)

Condition

Always 1qty at a time.

You have unlimited money.

One Time One Action

(Buy, Sell or stay)

First In First Out

Input Data

  • [100, 200, 400, 900, 300] => 1000
  • [100, 400, 100, 700, 600, 1200, 500] => 1900
  • [200, 400, 100, 200, 300, 500, 100, 900, 1000, 50, 550] =>2700
  • [950, 930, 510, 350, 160] => 1370
  • [30, 20, 20, 40, 60, 110, 10] => 160

Market Price

By Beavis28

Market Price

  • 220