Hi Stephan,
Writing trading algo is not trivial at all.
It seems trivial on paper but it is not in reality.
I have done this as my main job for the last 6 years or more. Wrote
thousands of lines of code.
There are many issues that people that have not done this before do not
consider. The main issue is TRADING COSTS.
I see you want to trade coins so I'm assuming you want to trade crypto.
Crypto has not just very high slippage but also trading fees (no fees right
now to trade stocks).
Start to ask yourself what is the trading frequency.
When you do backtesting try different trading frequencies and plot a graph
of final return vs trading frequency (when you include project costs). You
can come up with different measures of slippage but without a code that
actively deals with slippage (for example an Arrival Time algo) slippage
can be on average 0.2 % or higher per trade about 2x the fee costs. So when
you plot your curve you will see that there is an optimization curve that
will indicate the ideal trading time (a convex one). If you trade too often
your alpha disappears due to costs and if you trade too slowly you don't
trade enough to accumulate gains quickly enough.

Liquidity is another very important issue to consider and when we trade
crypto we stick to the 22 most liquid coins. Our algo trades a portfolio of
them.

Variability is also fundamental. One thing we discovered is that 2 runs of
the same algo can produce wildly different results if run even 5 minutes
apart. That is because even if your algo has some predictive power it would
be always dominated by noise and given the nature of compounding 2 paths
that are even 5 minutes apart will end up after a few months in very
different places. What I mean one version of your algo can make 20 % and
the other loses 30 %. So the only way to deal with that is to run several
versions of your algo separated by few minutes apart and settle on the
average result.

Our crypto code runs 20 versions. We trade about every 10 hours for each
version.
Anyway, you will find out soon an algo on paper is just an idealization
relative to what is going on with real trading. You need to build a very
robust platform that will have to deal with all sorts of signal exceptions,
time errors, servers going down, and many other inefficiencies that will
impact your final result.
After 6 years of working on such a platform that deals with slippage, and
that has redundancy to address different issues with continuity of trading
we are still struggling with these issues and improving very slowly. When
we think we ironed down all the possible problems another one is coming up.
Our theoretical algos should give us more than 3-4 x a year (even after
costs) but that is not what happens yet in reality because of all the
technical issues in real-life trading.

I'm interested in your results and if you want to have a discussion offline
on these issues I'm available. Please send a private email if you like.

Giovanni







On Fri, Sep 23, 2022 at 1:58 PM stefan.reich.maker.of.eye via AGI <
[email protected]> wrote:

> *Step 1: Position closing algorithm.*
>
> On new ticker value x of currency $coin do:
>   p = get our open position for $coin
>   if p exists:    // relativeValue is the position's PnL in percent under 
> leverage 1
>     p.relativeValue = (x/p.openingPriceWithFees-1)*p.direction*100
>     p.maxRelativeValue = max(p.maxRelativeValue, p.relativeValue)
>     pullbackThreshold = p.maxRelativeValue-pullback(p)
>
>     // LOSS (accept loss to circumvent risk escalation)
>     if p.relativeValue < -lossLimit:
>       close p
>
>     // SPONTANEOUS HAPPY CLOSE (position is positive & user-definable 
> criterion is fulfilled)
>     if p.relativeValue > minReasonableProfit and shouldHappyClose(p):
>       close p
>
>     // PULLBACK CLOSE (when current value falls significantly below the 
> all-time high)
>     if pullbackThreshold > 0 and p.relativeValue < pullbackThreshold:
>       close p
>
>
> We have *3 configuration options*:
>
>    - *lossLimit *- maximum accepted loss before leverage
>    - *pullback*(p) - maximum accepted relative pullback before closing a
>    positive position
>    - *shouldHappyClose*(p) - a user-supplied function that can randomly
>    return true for a position (that is in the plus!) to have it closed
>    immediately. There can be different reasons to do this.
>
>
> *Step 2: Position opening algorithm.*
>
> Now, the interesting thing is how to define the position opener.
>
> After all, closing a position is basically just milking the pig. You want
> to get as much out as you can, but it's not that complicated of a task.
>
> Opening a position, however,  is like finding the pig among hundreds of
> animals that look like pigs but don't actually give milk.
>
> *Anyone still following? :D*
>
> Anyway, my suggestion for the position opener - the magic piece that gives
> us the short and long signals! - is to simply open a position in the mind
> every time something happens to the ticker price. We also close these
> positions (mentally) when the above algorithm says so.
>
> And when any one of these positions becomes suitably positive, we
> basically assume the trend will continue and actually open a position of a
> very similar kind in real life.
>
> That might not be all there is to it though, I have a feeling the actual
> solution is a little more complicated still.
>
> *Step 3: Optimize the parameters*
>
> Remember, in the beginning we defined 3 parameters (2 of which are even
> functions). We should clearly just try different values for these and see
> how much profit we get in the simulation. This should be done for each
> crypto currency.
>
> A clear plan, right? Let's go then!!
> *Artificial General Intelligence List <https://agi.topicbox.com/latest>*
> / AGI / see discussions <https://agi.topicbox.com/groups/agi> +
> participants <https://agi.topicbox.com/groups/agi/members> +
> delivery options <https://agi.topicbox.com/groups/agi/subscription>
> Permalink
> <https://agi.topicbox.com/groups/agi/Ta2a8c93c499a68be-M5dae5cd93622425911c048f4>
>

------------------------------------------
Artificial General Intelligence List: AGI
Permalink: 
https://agi.topicbox.com/groups/agi/Ta2a8c93c499a68be-Mfc2f0c8d5e9cf4390056e628
Delivery options: https://agi.topicbox.com/groups/agi/subscription

Reply via email to