Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Apr 15, 2023
1 parent 3596548 commit 657695c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
```@meta
CurrentModule = Trading
```
Welcome to Trading.jl, a powerful algorithmic trading and backtesting package written in Julia.
Welcome to Trading.jl, a powerful event-driven algorithmic trading and backtesting package written in Julia.

It provides an easy-to-use framework for defining and executing trading strategies based on technical indicators, as well as backtesting these strategies on historical data.

Expand Down
18 changes: 11 additions & 7 deletions docs/src/strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
CurrentModule = Trading
```

As with any other functionality in `Trading`, `Strategies` are represented by `Systems` and thus are treated on completely equal footing with the core functionality.
There are three main parts that need to be implemented for a `Strategy` to be used: the `Systems`, the `Overseer.update` functions, and the `Overseer.requested_components` function.
This latter one will be used to determine which [`Indicator`](@ref Indicators) systems need to be running on the [`TickerLedgers`](@ref TickerLedger) in order to produce
the [`Indicators`](@ref Indicators) that are used by the `Strategy`.
The `update` function of a `Strategy` `System` is ran periodically after the `update` functions for the other `Systems` that make the rest of the [`Trader`](@ref) tick.
```@docs
Strategy
```
There are three main parts that need to be implemented for a [`Strategy`](@ref) to be used:
- a `System`
- the `Overseer.update` function
- the `Overseer.requested_components` function

This latter one will be used to determine which [`Indicator`](@ref Indicators) systems need to be executed on the data inside each [`TickerLedger`](@ref) in order to produce
the [`Indicators`](@ref Indicators) that are used by the [`Strategy`](@ref).

## Strategy Definition
As an example we will implement a very simple slow/fast moving average strategy, i.e. `SlowFast`.
The goal is that we can later use it in our [`Trader`](@ref) in to following way:

```julia
trader = Trader(broker; strategies = [Strategy(:slowfast, [SlowFast()], tickers=["stock1", "stock2"])])
trader = Trader(broker; strategies = [Strategy(:slowfast, [SlowFast()], tickers=["stock1"])])
```

We begin by defining the `SlowFast` `System` and the components that it requests to be present in [`TickerLedgers`](@ref TickerLedger).
Expand Down Expand Up @@ -146,6 +151,5 @@ See [`Slow Fast Strategy`](@ref slow_fast_id) for a full runnable version of thi
## References
```@docs
Trading.relative
Trading.Strategy
NewEntitiesIterator
```
12 changes: 11 additions & 1 deletion src/Components/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ end
TimeStamp(args...) = TimeStamp(current_time(args...))

"""
A `Stage` with a set of `Systems` that execute a strategy.
Strategy(name::Symbol, systems::Vector{System}; only_day = false, tickers = String[])
A strategy embodies a set of `Systems` that will run periodically, where each of the `Systems` should have a defined
`update(s::System, trader, ticker_ledgers)` function, with `ticker_ledgers` being the [`TickerLedgers`](@ref TickerLedger)
associated with each of the `tickers` that the strategy should be applied on.
!!! note
The last [`TickerLedger`](@ref) in `ticker_ledgers` is a "combined" ledger which can store data shared between all `tickers` for this strategy.
`only_day`: whether this strategy should only run during a trading day
"""
@component Base.@kwdef struct Strategy
stage::Stage
Expand Down
8 changes: 4 additions & 4 deletions src/Components/indicators.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
MovingStdDev{horizon, T}
The moving standard deviation of a value over timeframe of `horizon`.
The moving standard deviation of a value over a sliding window of `horizon`.
"""
@component struct MovingStdDev{horizon,T}
σ::T
Expand All @@ -12,7 +12,7 @@ Base.eltype(::Type{MovingStdDev{x,T}}) where {x,T} = T
"""
SMA{horizon, T}
The simple moving average of a value over a timeframe of `horizon`.
The simple moving average of a value over a sliding window of `horizon`.
"""
@component struct SMA{horizon,T}
sma::T
Expand All @@ -23,7 +23,7 @@ Base.eltype(::Type{SMA{x,T}}) where {x,T} = T
"""
EMA{horizon, T}
The exponential moving average of a value over timeframe of `horizon`.
The exponential moving average of a value over a sliding window of `horizon`.
"""
@component struct EMA{horizon,T}
ema::T
Expand All @@ -34,7 +34,7 @@ Base.eltype(::Type{EMA{x,T}}) where {x,T} = T
"""
Bollinger{horizon, T}
The up and down Bollinger bands for a value, over a timeframe of `horizon`.
The up and down Bollinger bands for a value, over a sliding window of `horizon`.
"""
@component struct Bollinger{horizon,T}
up::T
Expand Down

0 comments on commit 657695c

Please sign in to comment.