devalpha-io / devalpha-node

A stream-based approach to algorithmic trading and backtesting in Node.js
https://devalpha.io
GNU General Public License v3.0
246 stars 40 forks source link

generality of dashboard #7

Open unsaved opened 6 years ago

unsaved commented 6 years ago

It may well be that this isn't an issue at all, and I just need help understanding purpose or usage of the dashboard. If I should post questions like to this to the reddit algotrading community or elsewhere, please say so.

I read somewhere in the docs that backtesting and the dashboard are very general and will work for any data, not just market trading. But I can't even get it to work generally with market trading.

Is the purpose of the chart to display only your holdings? Because it if I make no context.order then it displays nothing useful, does not chart the feed values. If I place a single buy then it seems to chart the value of my holding according to subsequent feed events. If I make a buy and later a sell then it seems to chart the value of my holding based only on buy and sell price with no influence by feed event prices. Specifically, I buy at 1.00 (with no correspondence to any feed value) and later sell at 3.00 (with no correspondence to any feed value) and this is charted as a line from 1.00 to 3.00. So in this case the feed data has only indirect influence (if I use it when calculating buy or sell prices in my strategy function).

Why does context.order return false even though it gets successfully requested, created, placed, and filled? Maybe false indicates that it's a backtesting order?

I thought I remembered reading somewhere that order rejections included a reason string. For my rejection events I get back only the same attributes as the order itself. Not useful for troubleshooting.

Now for the really flaky parts.

If I make buys at price 1.00, with my fake stocks, regardless of the feed prices, it goes through, and I can later sell them at this same price. Buys at other prices are rejected. Why a limit order would succeed when it is nowhere near the market prices, I don't know. Do you use some back-trading rules for accepting limit prices, and somehow allow "1.00"? In this strategy callback I can place multiple orders for different stocks at price 1.00 and they all succeed.

But context.order is only working for me in the first strategy callback in which I attempt it. As I said, multiple buys at 1.00 will succeed for multiple stocks. But if I try the same thing (to buy any stock) in a following strategy callback, the buy attempts are always rejected. It would be awesome if you would provide reason detail with rejection events.

I'm attaching my exercise script.

playTrader.js.txt

fhqvst commented 6 years ago

I appreciate your thoughts, and I'm quite sure others find them useful too. Feel free to open issues here or discuss it on Reddit - both ways are fine in my opinion!

So the purpose of the chart is to show you the total value of your current positions + cash. Currently, only limit orders are supported, which means that it is you (the author) of the strategy who must define at which price levels orders are executed.

However, if the payload is formatted in a certain way (it has these properties: identifier, open, high, low, close), DevAlpha will recognize it as a OHLC-bar, and update the value of your holdings accordingly.

Example: You receive a feed item which is an OHLC-bar with a uniform price of 3.00. Your strategy tells DevAlpha to execute an order at 10000.00. DevAlpha assumes that this is possible, and executes the order for you (even though the last OHLC-bar said that the best price at that time was 3.00). If you owned shares of the instrument before, then the total value of your holdings is updated accordingly.

Regarding your question about subsequent orders not being executed, I see that you've set startCapital: 1. Try setting startCapital: 10000 and see what happens.

Lastly, the reason context.order always return false is because it is merely a call to Highlands stream.write, which in turn simply calls the native Writable.write. Read more here.

Subsequent events will tell you if the order was placed, rejected or failed, so the return value doesn't mean anything in this setting. I should probably have it return undefined instead.

unsaved commented 6 years ago

I'm out of time for today, but I can see I'll get a lot farther with the info you provided. A lot of my problem was probably due to me forgetting about startCapital value. Thanks for spotting that!

unsaved commented 6 years ago

Based on your reply above, in addition to requiring the specified 5 event properties, since "the purpose of the chart is to show you the total value of your current positions + cash", I guess that the dashboard is also usable only in conjunction with context.order invocations. I.e. there's no way to chart anything unless both context.order is invoked, and events populate the 5 required properties?

I wanted to leverage your dashboard tool to chart things other than my holdings, such as indicator values or custom calculations based on multiple qualifying stocks. I guess this isn't feasible?