https://github.com/louisponet/trading.jl
Algorithmic trading and backtesting framework in pure julia
https://github.com/louisponet/trading.jl
algotrading alpaca-markets alpaca-trading-api backtesting-trading-strategies entity-component-system
Last synced: 5 months ago
JSON representation
Algorithmic trading and backtesting framework in pure julia
- Host: GitHub
- URL: https://github.com/louisponet/trading.jl
- Owner: louisponet
- License: other
- Created: 2022-05-08T23:09:41.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-29T15:47:13.000Z (almost 2 years ago)
- Last Synced: 2025-03-30T10:31:32.992Z (6 months ago)
- Topics: algotrading, alpaca-markets, alpaca-trading-api, backtesting-trading-strategies, entity-component-system
- Language: Julia
- Homepage: https://louisponet.github.io/Trading.jl/
- Size: 9.76 MB
- Stars: 61
- Watchers: 6
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Trading.jl
[](https://github.com/louisponet/Trading.jl/actions?query=workflow%3ACI)
[](https://codecov.io/gh/louisponet/Trading.jl)
[](https://louisponet.github.io/Trading.jl/dev/)
[](https://louisponet.github.io/Trading.jl/stable/)
[](https://pkgs.genieframework.com?packages=Trading)This is an algorithmic trading and backtesting package written in Julia. It provides a framework for defining and executing trading strategies based on technical indicators, as well as backtesting these strategies on historical data.
Behind the scenes it relies on an ECS paradigm as implemented by [Overseer.jl](https://github.com/louisponet/Overseer.jl), making it extremely easy to extend.# Simple Example
To define a trading strategy, users need to implement a Julia struct with an update function that defines the trading logic. The update function is called periodically by the framework, and has access to tick data for the specified assets, as well as any technical indicators requested by the strategy.```julia
struct StratSys <: System endOverseer.requested_components(::StratSys) = (Open, Close, SMA{20, Close}, SMA{200, Close})
function Overseer.update(s::StratSys, trader, asset_ledgers)
for ledger in asset_ledgers
for e in new_entities(ledger, s)
#Trading logic goes here
end
end
end
```The package includes several built-in technical indicators, such as simple moving averages, relative strength index, and exponential moving averages, but users can also define their own custom indicators.
To execute a trading strategy in real-time, users can create a Trader object with the desired strategies and assets, and connect it to a real-time data source through the different broker APIs.
```julia
broker = AlpacaBroker("", "")strategy = Strategy(:strat, [StratSys()], assets=[Stock("AAPL")])
trader = Trader(broker, strategies=[strategy])
start(trader)
```If one wants to backtest a trading strategy on historical data, users can instead use `BackTester` instead of `Trader` with the desired data range, interval, and strategies. The backtester will simulate the behavior of a realtime trader on the specified data. Afterwards a [`TimeArray`](https://github.com/JuliaStats/TimeSeries.jl) can be created with the data from the `trader`, and used for performance analysis.
```julia
trader = BackTester(HistoricalBroker(broker),
strategies=[strategy],
start = ,
stop = ,
dt = )start(trader)
ta = TimeArray(trader)
using Plots
plot(ta[:value])
```The package is designed to be flexible and customizable, and can be extended with new technical indicators, trading strategies, and data sources.
See [Documentation](https://louisponet.github.io/Trading.jl/dev) for more details.
# Future Roadmap
- Improved performance analysis, statistics
- Implement standard plotting functionality
- [`Trader`](@ref) loading and saving
- Implement further signals and [`Indicators`](@ref)
- Backtest comparisons
- Support for different [`Brokers`](@ref)