Skip to content

Commit

Permalink
update backterst
Browse files Browse the repository at this point in the history
  • Loading branch information
ryqdev committed Jun 9, 2024
1 parent 58f2825 commit 17d97bd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[config]
broker = "Basetest"
symbol = "TLT"
symbol = "MSFT"
time = "Default"
strategy = "Test"
cash = 100_000
6 changes: 3 additions & 3 deletions src/cmds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ impl Golden for BackTestGolden {
let order = self.strategy.next(&bar);
let cash = self.broker.cash.last().unwrap();
let position = self.broker.position.last().unwrap();
log::info!("Cash: {:?}, Position: {:?}", cash, position);
log::info!("{}: Cash: {:?}, Position: {:?}", bar.date, cash, position);
match order.action {
Action::Buy => {
log::info!("Buy: {:?}", order);
if *cash < 0.0 {
if *cash <= 0.0 {
log::error!("cash is smaller than 0. Cannot buy");
self.broker.cash.push(*cash);
self.broker.position.push(*position);
Expand All @@ -80,7 +80,7 @@ impl Golden for BackTestGolden {
}
Action::Sell => {
log::info!("Sell: {:?}", order);
if *position < 0.0 {
if *position <= 0.0 {
log::error!("position is smaller than 0. Cannot sell");
self.broker.cash.push(*cash);
self.broker.position.push(*position);
Expand Down
2 changes: 1 addition & 1 deletion src/feeds/csv/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn get_bar_from_csv(symbol: &str) -> Result<Vec<Bar>> {
.map(|line| {
let record = line?;
Ok(Bar {
date: OffsetDateTime::now_utc(),
date: record.date,
open: record.open,
high: record.high,
low: record.low,
Expand Down
2 changes: 1 addition & 1 deletion src/feeds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait BaseData{}

#[derive(Clone, Debug)]
pub struct Bar {
pub date: OffsetDateTime,
pub date: String,
pub open: f64,
pub high: f64,
pub low: f64,
Expand Down

0 comments on commit 17d97bd

Please sign in to comment.