Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import csv
import logging
import os
import platform
from datetime import datetime
from decimal import Decimal, DecimalException
from pathlib import Path

import pytest

from stock_indicators._cslib import clr
from stock_indicators.indicators.common import Quote # pre-initialized
from stock_indicators.indicators.common import Quote
from stock_indicators.logging_config import configure_logging


Expand Down Expand Up @@ -64,6 +61,10 @@ def parse_date(date_str):
return datetime.now()


@pytest.fixture(scope="session")
def raw_data(filename: str = 'Default'):
return get_data_from_csv(filename)

@pytest.fixture(scope="session")
def quotes(days: int = 502):
rows = get_data_from_csv("Default")
Expand Down
23 changes: 23 additions & 0 deletions benchmarks/test_benchmark_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,26 @@ def test_benchmark_wma(self, benchmark, quotes):

def test_benchmark_zig_zag(self, benchmark, quotes):
benchmark(indicators.get_zig_zag, quotes)

def test_benchmark_converting_to_IndicatorResults(self, benchmark, quotes):
from stock_indicators._cslib import CsIndicator
from stock_indicators.indicators.common.enums import CandlePart
from stock_indicators.indicators.common.quote import Quote
from stock_indicators.indicators.sma import SMAResults, SMAResult

candle_part: CandlePart = CandlePart.CLOSE
lookback_periods = 12
quotes = Quote.use(quotes * 1000, candle_part) # Error occurs if not assigned to local var.
results = CsIndicator.GetSma(quotes, lookback_periods)

benchmark(SMAResults, results, SMAResult)

def test_benchmark_converting_to_CsDecimal(self, benchmark, raw_data):
from stock_indicators._cstypes import Decimal as CsDecimal
raw_data = raw_data * 1000

def convert_to_quotes(rows):
for row in rows:
CsDecimal(row[2])

benchmark(convert_to_quotes, raw_data)
Loading