ZenFlow.Core
1.0.0
dotnet add package ZenFlow.Core --version 1.0.0
NuGet\Install-Package ZenFlow.Core -Version 1.0.0
<PackageReference Include="ZenFlow.Core" Version="1.0.0" />
<PackageVersion Include="ZenFlow.Core" Version="1.0.0" />
<PackageReference Include="ZenFlow.Core" />
paket add ZenFlow.Core --version 1.0.0
#r "nuget: ZenFlow.Core, 1.0.0"
#:package ZenFlow.Core@1.0.0
#addin nuget:?package=ZenFlow.Core&version=1.0.0
#tool nuget:?package=ZenFlow.Core&version=1.0.0
ZenFlow - Forex Quantitative Trading Engine
<div align="center">
A modern, high-performance forex quantitative trading engine built with .NET 10
Features • Quick Start • Documentation • Examples
</div>
Overview
ZenFlow is a comprehensive quantitative trading engine designed for forex markets. Inspired by QuantConnect/Lean architecture, it provides a complete framework for developing, backtesting, and deploying algorithmic trading strategies.
Key Highlights
- .NET 10 - Built on the latest .NET platform
- 143 Tests - Comprehensive test coverage ensuring reliability
- Modular Architecture - Clean separation of concerns
- QuantConnect Compatible API - Familiar interface for algorithm development
- Multiple Data Sources - Support for CSV, JSON, API, and real-time feeds
- Rich Indicator Library - SMA, EMA, RSI, MACD, Bollinger Bands, and more
Features
Core Components
| Component | Description |
|---|---|
| Algorithm Framework | Base classes and interfaces for strategy development |
| Order Management | Market, Limit, Stop-Market, Stop-Limit orders |
| Portfolio System | Position tracking, cash management, performance metrics |
| Data Engine | Historical data loading, real-time data feeds |
| Backtest Engine | Event-driven simulation with realistic fills |
| Indicator Library | Technical analysis indicators |
Technical Indicators
- SimpleMovingAverage (SMA) - Simple moving average
- ExponentialMovingAverage (EMA) - Exponential moving average
- RelativeStrengthIndex (RSI) - Relative strength index
- MovingAverageConvergenceDivergence (MACD) - MACD indicator
- BollingerBands (BB) - Bollinger Bands volatility indicator
Order Types
| Order Type | Description |
|---|---|
MarketOrder |
Execute immediately at market price |
LimitOrder |
Execute at specified price or better |
StopMarketOrder |
Market order triggered at stop price |
StopLimitOrder |
Limit order triggered at stop price |
MarketOnOpenOrder |
Execute at market open |
MarketOnCloseOrder |
Execute at market close |
Project Structure
ZenFlow/
├── src/
│ └── ZenFlow.Core/
│ ├── Algorithm/ # Strategy framework
│ │ ├── Framework/ # Alpha, Portfolio, Execution models
│ │ └── Strategies/ # Example strategies
│ ├── Brokerage/ # Brokerage implementations
│ ├── Data/ # Market data handling
│ ├── Engine/ # Trading engine core
│ ├── Indicators/ # Technical indicators
│ ├── Trading/ # Orders, Portfolio, Securities
│ └── Examples/ # Usage examples
├── tests/
│ └── ZenFlow.Core.Tests/ # Unit tests (143 tests)
└── samples/ # Sample applications
Quick Start
Prerequisites
- .NET 10 SDK
- Visual Studio 2022 or VS Code with C# extension
Build and Test
# Clone or navigate to the project
cd ZenFlow
# Build the solution
dotnet build
# Run all tests
dotnet test
Create Your First Strategy
using ZenFlow.Algorithm;
using ZenFlow.Data.Market;
using ZenFlow.Indicators;
public class MyFirstStrategy : QCAlgorithm
{
private SimpleMovingAverage _sma;
private Symbol _eurusd;
public override void Initialize()
{
SetCash(100000);
SetStartDate(2023, 1, 1);
SetEndDate(2023, 12, 31);
_eurusd = AddForex("EURUSD", Resolution.Hour);
_sma = SMA(_eurusd, 20);
}
public override void OnData(Slice data)
{
if (!_sma.IsReady) return;
if (data[_eurusd].Price > _sma.Current)
{
SetHoldings(_eurusd, 0.1); // Buy 10%
}
else
{
Liquidate(_eurusd); // Close position
}
}
}
Examples
Moving Average Cross Strategy
public class MovingAverageCrossStrategy : QCAlgorithm
{
private ExponentialMovingAverage _fastEma;
private ExponentialMovingAverage _slowEma;
private Symbol _symbol;
public override void Initialize()
{
SetCash(100000);
_symbol = AddForex("EURUSD", Resolution.Hour);
_fastEma = EMA(_symbol, 10);
_slowEma = EMA(_symbol, 30);
}
public override void OnData(Slice data)
{
if (!_fastEma.IsReady || !_slowEma.IsReady) return;
var holding = Portfolio[_symbol];
var fastAboveSlow = _fastEma.Current > _slowEma.Current;
if (fastAboveSlow && holding.Quantity <= 0)
{
MarketOrder(_symbol, 10000);
}
else if (!fastAboveSlow && holding.Quantity > 0)
{
Liquidate(_symbol);
}
}
}
RSI Mean Reversion Strategy
public class RsiStrategy : QCAlgorithm
{
private RelativeStrengthIndex _rsi;
private Symbol _symbol;
public override void Initialize()
{
SetCash(100000);
_symbol = AddForex("GBPUSD", Resolution.Hour);
_rsi = RSI(_symbol, 14);
}
public override void OnData(Slice data)
{
if (!_rsi.IsReady) return;
if (_rsi.Current < 30) // Oversold
{
MarketOrder(_symbol, 10000);
}
else if (_rsi.Current > 70) // Overbought
{
Liquidate(_symbol);
}
}
}
Documentation
Core Concepts
Algorithm Lifecycle
- Initialize() - Set up strategy parameters, indicators, and subscriptions
- OnData(Slice) - Process incoming market data and make trading decisions
- OnOrderEvent(OrderEvent) - Handle order fills, cancellations, etc.
- OnEndOfAlgorithm() - Final cleanup and reporting
Portfolio Management
// Access portfolio properties
var cash = Portfolio.Cash;
var equity = Portfolio.TotalPortfolioValue;
var holdings = Portfolio[_symbol];
// Position information
var quantity = holdings.Quantity;
var avgPrice = holdings.AveragePrice;
var unrealizedPnL = holdings.UnrealizedProfit;
Order Management
// Market order
var ticket = MarketOrder(_symbol, 10000);
// Limit order
var ticket = LimitOrder(_symbol, 10000, limitPrice: 1.0850);
// Stop order
var ticket = StopMarketOrder(_symbol, -10000, stopPrice: 1.0800);
// Check order status
if (ticket.Status == OrderStatus.Filled)
{
Log($"Order filled at {ticket.AverageFillPrice}");
}
Performance Metrics
The backtest engine calculates comprehensive performance metrics:
| Metric | Description |
|---|---|
| Total Return | Overall profit/loss percentage |
| Annualized Return | Return normalized to yearly rate |
| Max Drawdown | Largest peak-to-trough decline |
| Sharpe Ratio | Risk-adjusted return metric |
| Sortino Ratio | Downside risk-adjusted return |
| Win Rate | Percentage of profitable trades |
| Profit Factor | Gross profit / Gross loss |
Testing
ZenFlow has comprehensive test coverage:
# Run all tests
dotnet test
# Run specific test category
dotnet test --filter "FullyQualifiedName~Indicators"
# Run with coverage
dotnet test --collect:"XPlat Code Coverage"
Test Categories
- Indicator Tests - SMA, EMA, RSI, MACD, Bollinger Bands
- Order Tests - Order creation, validation, lifecycle
- Engine Tests - Matching engine, brokerage simulation
- Data Tests - Data loading, parsing, historical data
Roadmap
Phase 1-5 (Completed)
- Core project structure
- Order system implementation
- Data sources and market data
- Trading engine core
- Indicator library
- Comprehensive test suite (143 tests)
Phase 6 (In Progress)
- Example strategies
- Documentation
- API reference generation
- Advanced examples
Future Phases
- Live trading support
- Multiple broker integrations
- Web-based dashboard
- Machine learning indicators
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
- Fork the repository
- Create a feature branch
- Write tests for new features
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by QuantConnect/Lean
- Built with .NET 10 and modern C# practices
- Testing powered by xUnit and FluentAssertions
<div align="center">
ZenFlow - Empowering algorithmic forex trading
</div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- Serilog (>= 4.2.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 106 | 4/15/2026 |
Initial release of ZenFlow.Core - Forex quantitative trading engine