mirror of
https://github.com/KhizarImran/backtestingfx.git
synced 2026-08-09 10:17:52 +00:00
feat: Position __repr__ and DataFrame column validation
This commit is contained in:
@@ -91,6 +91,11 @@ class Backtest:
|
|||||||
self._quote_to_account = quote_to_account
|
self._quote_to_account = quote_to_account
|
||||||
|
|
||||||
def _to_bars(self):
|
def _to_bars(self):
|
||||||
|
required = {"open", "high", "low", "close"}
|
||||||
|
missing = required - set(self._df.columns.str.lower())
|
||||||
|
if missing:
|
||||||
|
raise ValueError(f"DataFrame missing required columns: {sorted(missing)}")
|
||||||
|
|
||||||
bars = []
|
bars = []
|
||||||
for idx, row in self._df.iterrows():
|
for idx, row in self._df.iterrows():
|
||||||
if isinstance(idx, pd.Timestamp):
|
if isinstance(idx, pd.Timestamp):
|
||||||
|
|||||||
@@ -53,6 +53,19 @@ pub struct Position {
|
|||||||
pub take_profit: Option<f64>,
|
pub take_profit: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pymethods]
|
||||||
|
impl Position {
|
||||||
|
fn __repr__(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"Position(id={}, {} {:.2} lots @ {:.5})",
|
||||||
|
self.id,
|
||||||
|
if self.is_long { "LONG" } else { "SHORT" },
|
||||||
|
self.lot_size,
|
||||||
|
self.entry_price,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Trade {
|
pub struct Trade {
|
||||||
// the actual trade
|
// the actual trade
|
||||||
|
|||||||
Reference in New Issue
Block a user