

Show HN: Simple algorithmic trading in JavaScript - Cloud9Trader
https://www.cloud9trader.com

======
chollida1
There was a company last week that showed off their bitcoin algos and I wrote
a comment that basically said don't use them and I felt bad about it for the
rest of the week. I'll try to just be positive here:)

To weigh in on the mention of using doubles for finance....

Using double for finance, perfectly fine. All trading systems I've seen use
double, from HFT systems to deep learning AI systems that open and close
potions over months. Double is fine for most algo trading, heck the exchanges
and dark pools I've talked with use double.

What you can possibly do with this.

1) Learn how to write the logic of an trading algorithm.

2) learn the basics of technical trading, with MACD, Keltner channels, vortex
and Bollinger band indicators. They've definitely put the time in to getting
the indicators that FX traders like to use.

What you can't do with this system.

1) React to currency fluctuations on a tick by tick basis. FX is just so fast
and precise, there is a reason that professional FX traders mix FX spot quotes
from multiple sources, we use 4 at the fund I work at and some use up to 10
sources. There is also a reason why FX is quoted to 4 decimal places while
equities are to 2, sometimes 3 for penny stocks.

2) Use this in a real world setting. I can't see any privacy policy or
contract indicating what happens when shit goes wrong. We are talking about
money here, you can't just half ass this kind of thing.

Plus they use FXCM which had this new out about them:

[http://online.wsj.com/news/articles/SB1000142405270230425560...](http://online.wsj.com/news/articles/SB10001424052702304255604579406640141660638)

> LONDON—Foreign-exchange trading firm FXCM Inc. FXCM +0.08% agreed to pay
> fines and refunds totaling almost £10 million ($16.7 million) to settle
> allegations by a U.K. financial regulator that the company withheld profits
> from clients and failed to inform British authorities that it was under
> investigation in the U.S.

> The Financial Conduct Authority said that U.K. units of FXCM withheld £6
> million from customers on foreign-exchange transactions between August 2006
> and December 2010. The regulator said the broker pocketed profits when
> exchange rates moved in its customers' favor while a trade was in process,
> but it passed on losses that occurred on other trades.

~~~
Cloud9Trader
A lean algorithm will comfortably execute every tick even in a busy market. Of
course if it can't be processed before the next tick comes in, subsequent
executions will run late, though we leave this up to the trader and hope to
just provide the most performant execution environment we can.

We find no issues running scripts of reasonably high complexity. Of course if
you have a particularly heavy algorithm it may be better suited to running at
interval close.

With regard to legal position, you're absolutely right. While we're in beta
you can connect to live broker accounts, though we are blocking order requests
from actually being sent. We want to be water tight both technically and
legally before we full launch with regulatory authorization, lifting this
restriction and allowing real money to be risked.

As with brokers, we just want to support as many as we can. FXCM were a
natural first choice for integration as they have excellent support for API
solutions and have the most fully featured FIX implementation we've come
across. Of course it's up to the trader to establish if any conflict of
interest scenario exists between themselves and the broker.

~~~
topbanana
If the algo falls behind, it's usually better to throw away intermediate data.

------
mikkom
> We believe algorithmic trading is simple

Trading might be simple but being profitable definitely is not.

~~~
brownegg
I'm in the "professional automated trading" space. This is by far the most
common vendor mistake. "We make trading simple!" is pretty much a surefire way
to mediocrity at best.

"We make tax law simple!"

"We make heart surgery simple!"

^^ similar silly things, only you don't ever see them

The thing is, no one actually DOES make anything simpler. They just restrict
the toolset with which you can solve problems to things that work for the 80%
cases.

~~~
sillysaurus3
Would you mind giving any examples?

~~~
stzup7
Quick example, I want to build a dynamic portfolio based on a subset of S&P
500, with no sectors exposure, no market exposure (delta and beta flat), no
capitalisation exposure, and I want to avoid trading a stock from one week
before until one week after their earning announcements. This is a very simple
example of a common portfolio universe but tools like quantopian and
cloud9trader (even though the latter doesn't support stocks yet so they're out
of scope here) just don't provide the required data. I can't find an index
historical composition, security data doesn't include its market cap, its
sector, the next earnings announcement date. I can't even start working on my
signals since I'm unable to select my stocks.

~~~
Iftheshoefits
I don't think this platform is for equities (yet?). They only support FXCM,
which is a spot FX outfit. Based on the pricing, it seems to me these guys are
targeting, mainly, retail FX traders.

------
pathikrit
Looks cool! Another: [https://www.quantopian.com](https://www.quantopian.com)

~~~
BozeWolf
This is actually interesting if you combine it with the other HN thread
currently on the FP. Its about pyrasite.com, which allows you to read/write
into another python process.
[https://news.ycombinator.com/item?id=8160149](https://news.ycombinator.com/item?id=8160149)

Im wondering how they do this.

~~~
neuralk
You linked to the wrong thread. I believe you meant this one:
[https://news.ycombinator.com/item?id=8161586](https://news.ycombinator.com/item?id=8161586)

------
CmonDev
Writing critical code in JavaScript? That's interesting.

~~~
ris
Hey, well, if you're going to engage in a practice that potentially
destabilizes the entire global economy, why _not_ do it in javascript?

------
radikalus
I hope to not come off as too critical, but there's a ridiculously wide margin
between this and what trading firms in the low latency space do.

I don't know of a single firm that's successful in the time horizon that a lot
of pseudo-HFT systems operate in. (The 10ms-3s range) And that's assuming an
ideal fee situation...

Most of the people ignoring the LL arms race target RV opportunities on the
30s+ range. This involves taking a pretty big step back from
microsctructure/toxicity models.

~~~
eastbayjake
> Most of the people ignoring the LL arms race target RV opportunities on the
> 30s+ range. This involves taking a pretty big step back from
> microsctructure/toxicity models.

Would you mind explaining more about this?

------
jaredbroad
Type safety lets you avoid all sorts of wonderful JS bugs :)
[https://www.quantconnect.com](https://www.quantconnect.com)

~~~
wwwwwwwwww
who needs type safety when you have all the web scale of javascript?

------
MalcolmDiggs
Great concept, looking forward to checking it out. Just curious, is this the
same team that did Cloud9IDE? (c9.io) or just a naming coincidence?

~~~
Cloud9Trader
Nope, purely naming coincidence... at the moment only aspiring to provide as
excellent a development workspace as Cloud9IDE does.

------
cwmma
So there is a reason you don't see much financial stuff written in JavaScript,
doubles plus financial really don't mix.

~~~
sillysaurus3
A double can store every integer from -2^53 to 2^53, which seems sufficient to
do financial work.

2^53 is 9,007,199,254,740,992

If you want to denote that the last three digits are for fractional dollars
(i.e. each integer represents 1/10th of a penny) then you can store any
monetary value from -$9 trillion to $9 trillion.

EDIT: Note that it's tempting to think that you can skip converting decimal
currency to integer as long as you only use <= 3 digits after the decimal and
you're storing values of less than 9 trillion, i.e. it's tempting to think
you're safe storing a value like $1,283.212 directly in a double without
converting to integer. But I'm pretty sure that's mistaken. You always need to
convert to integer so that you're storing 1,283,282 in a double, not
$1,283.212

The reason is because certain decimal values which can be represented in base
10 can't be represented in base 2. For example, $0.1 can't be stored into a
double as-is; if you try to store 0.1 into a double, you'll get:

    
    
      0.1000000000000000055511...
    

which is where the inaccuracies can start to come into play. Whereas if you
convert $0.1 to integer, you'll be storing the value 100 into a double, which
comes out to exactly 100 without any error.

Of course, the error may be so small as to be insignificant, but the point is,
I'm absolutely certain that integers between -2^53 and 2^53 can be perfectly
represented by doubles, but I'm not certain that <= 3 digits of decimal
precision can always be accurately represented by doubles for values of less
than 9 trillion.

EDIT2: You have to be careful when converting between currencies, too. For
example, right now $2 = 204 yen. If you're storing yen, 2^53 yen is different
from 2^53 one-tenth-pennies, so the max value that you can store is specific
to each currency. This seems like potentially a tricky problem, and may be
what the parent commenter was referring to when saying doubles aren't so good
for financial work. Still, though, 2^53 integers of precision may be
sufficient regardless of which currency you're using.

~~~
Nelkins
You're right, that's why some languages have built in data types that take
care of this issue for you (i.e. decimal in C# or BigDecimal in Java)[1].

[1] [http://stackoverflow.com/questions/3730019/why-not-use-
doubl...](http://stackoverflow.com/questions/3730019/why-not-use-double-or-
float-to-represent-currency)

------
foenv
Sorry if I missed it - I couldn't see on your site which brokers you intend to
connect with for live trading. Thanks

~~~
Cloud9Trader
We currently support live connections to FXCM. The welcome page gives you the
option of choosing a demo account or sticking in FXCM details.

We will be adding a wide selection of brokers to that list and will prioritize
on basis of demand.

Please let us know if there are any particular brokers you'd like us to
support.

~~~
dingdingdang
Integration with Oanda would be great.

~~~
Cloud9Trader
Oanda offer FIX connectivity, so very doable - we've already built FIX
adapters in NodeJS. Will get the ball rolling.

~~~
smrtinsert
Having worked with FIX, I feel for you.

------
jgunaratne
It looks like this is only for currency trading at the moment. Do they allow
other assets to be traded?

~~~
Cloud9Trader
Currently FXCM (the first broker we've integrated with - more to come) offer
forex in the US and also CFDs on indices, treasury and metals elsewhere.

------
ErikRogneby
Could anyone find a list of what markets this supports?

------
hliyan
Your login, register and demo links are not functioning.

~~~
Cloud9Trader
Thanks. Can't see any issues our side and getting plenty of successful
registrations. Which browser please?

~~~
hliyan
Chrome 36. Refresh solved the problem (seems the buttons silently fail if
there are network issues). Now having trouble connecting to the broker
servers. Network on my end is now fine, though.

I was waiting to see the thing in action before commenting, but here goes
anyway. What are your latencies like (market data and orders)? Do your algo's
have to depend entirely on current indicators/market data, or is there a way
to use historical data? I'm a former HFT/algorithmic trading systems dev
myself and the performance requirements in that particular domain was pretty
high. At one point, even C++ and close-packed binary data transfer wasn't
enough. I was wondering how you're managing with Javascript?

~~~
Cloud9Trader
Please let me know if you're continuing to have issues. All seems fine my end.

You can stick the following in your browser console to log server latency
stamps on incoming market data:

require(["registry"], function (registry) { var instrument =
registry.get("instruments").get("EUR/USD"); instrument.on("tick", function
(data) { console.log("Server latency (ms):", data.get("serverLatency")); });
});

Of course replace "EUR/USD" for whichever instrument you want to monitor.
10-20ms is typical for comms between our instances and the brokers (we get
similar results for outgoing trade execution requests, factoring in the round
trip).

Our stack is largely JavaScript. We've found NodeJS to be blisteringly fast
and lending itself perfectly for this kind of application (low memory, high
throughput, heavy processing).

We have a backesting framework for running against historical data. Do you
have a requirement for pulling historical data into an algorithm during live
trading? We haven't included this in out API, though it would be fairly
trivial to implement. It's key though that algos run with as little in memory
data as possible. We also include a framework for writing your own custom
technical indicators. These are naturally set up to pull historical data so
may be what you're after. These and the built in indicators can be used in
your script by just calling e.g. sma(10)

~~~
hliyan
Works after a re-login. Very nice!! Two final questions:

1\. Does the API allow writing an algorithm that deals with more than one
instrument?

2\. Thought about including Bitcoin?

~~~
Cloud9Trader
Thanks!

Currently the API doesn't support multiple instruments though an individual
trading session already pulls in whatever currency pairs are required to
convert from term currency to your account currency to calculate unrealized
profit and to allow you to set quantity in as a risk percentage of account
balance... basically not much work involved in supporting. Will get it
prioritised.

Definitely would like to include Bitcoin and are looking into our options at
the moment.

------
CWIZO
Good job Kafton :) Glad you released it :)

~~~
Cloud9Trader
Ha! thanks buddy!

