Skip to main content

Analyze stock

Project description

kabutobashi

pytest codecov Code style: black Imports: isort Checked with mypy

PythonVersion PiPY Documentation Status

Core Concept

@block-decorator and Flow-class is important. @block automatically generates input and output functions, allowing you to focus solely on the processing. Flow allows you to focus solely on the process flow and input parameters.

About @block-decorator

simple decorator is like below.

def simple_decorator(func):
    def wrap_func() -> str:
        res = func()
        return f"Hello, {res}"
    return wrap_func


@simple_decorator
def world() -> str:
    return "world"


world()  # => "Hello, world"

A decorator is something that dynamically generates and adds processes to functions or classes, similar to its name.

First, prepare a function as follows and decorate it with @block.

from kabutobashi import block

@block()
class UdfBlock:
    term: int = 10

    def _process(self):
        return {"doubled_term": self.term * 2}

The classes above is equivalent to the following class definition.

import pandas as pd
from kabutobashi.domain.entity.blocks import BlockGlue

class UdfBlock:
    series: pd.DataFrame = None
    params: dict = None
    term: int = 10
    block_name: str = "udf_block"

    def _process(self) -> dict:
        return {"doubled_term": self.term * 2}
    
    def process(self) -> BlockGlue:
        # _process() method can be Tuple[Optional[dict], Optional[pd.DataFrame]]
        res = self._process()
        return BlockGlue(params=res, series=None, block_outputs={})

    def factory(self, glue: BlockGlue) -> "UdfBlock":
        # Omitted. In reality, processes are described.
        ...

    def _factory(self, glue: BlockGlue) -> dict:
        # Omitted. In reality, processes are described.
        ...

    def glue(self, glue: BlockGlue) -> BlockGlue:
        # Omitted. In reality, processes are described.
        ...

In classes decorated with @block, it is not recommended to execute the __init__() method. Instead, it is recommended to use the factory() class-method.

factory() method description. process() method description. glue() method description.

sequenceDiagram
  autonumber
  participant G as glue()
  participant UC as UdfBlock::class
  create participant S1 as factory()
  UC->>S1: create
  create participant S2 as _factory()
  UC->>S2: create or defined by user
  create participant P1 as process()
  UC->>P1: create
  create participant P2 as _process()
  UC->>P2: create or defined by user
  Note over S1: Generate udf_block_instance
  G->>+S1: Request
  S1->>+S2: Request
  Note over S2: User can modify _factory()
  S2-->>S2: get params from glue
  S2-->>S2: get series from glue
  S2-->>-S1: params and series
  create participant UI as UdfBlock::instance
  S1->>UI: UdfBlock(params, series)
  S1->>UI: setattr params to udf_block_instance
  S1-->>-G: udf_block_instance
  G->>+UI: udf_block_instance.process()
  UI->>+P1: process()
  Note over P1: execute process()
  P1->>P2: Request
  Note over P2: execute user defined function
  P2-->>P1: params or series
  P1-->>-UI: BlockGlue(params, series)
  UI-->>-G: block_glue_instance

Up to this point, the use of the @block decorator with classes such as UdfClass has described, but using the Block class on its own is not intended. Please read the following explanation of the Flow class for more details.

About Flow-class

Blocks are meant to be combined.

Processes always consist of combinations of multiple simple operations. And the only tedious part is aligning their inputs and outputs.

Therefore, in Flow-class, it automatically resolves the sequence of those processes for users, as long as you provide the initial values.

usage

import kabutobashi as kb

# n日前までの営業日の日付リストを取得する関数
target_date = "2020-01-01"
date_list = kb.get_past_n_days(target_date, n=40)

initialize Database

import kabutobashi as kb
kb.KabutobashiDatabase().initialize()

# add data
kb.crawl_info_multiple(code="1375", page="1", database_dir="...")
kb.crawl_info_multiple(code="1375", page="2", database_dir="...")
kb.crawl_info_multiple(code="1375", page="etc...", database_dir="...")

# add data daily
kb.crawl_info(code="1375", database_dir="...")

# analysis and add data
kb.analysis(code="1375", database_dir="...")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kabutobashi-0.8.7.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

kabutobashi-0.8.7-py3-none-any.whl (56.4 kB view details)

Uploaded Python 3

File details

Details for the file kabutobashi-0.8.7.tar.gz.

File metadata

  • Download URL: kabutobashi-0.8.7.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1025-azure

File hashes

Hashes for kabutobashi-0.8.7.tar.gz
Algorithm Hash digest
SHA256 26b1b575addf0e621acb78f6b8f893c7b7745a364ccbdb245bc993206d821f89
MD5 10e692040ac391cf5b9b9495dccbadef
BLAKE2b-256 769167713d64c5aa88332d107d3ef48012e1a87eff54e945c37278af4edd55ad

See more details on using hashes here.

File details

Details for the file kabutobashi-0.8.7-py3-none-any.whl.

File metadata

  • Download URL: kabutobashi-0.8.7-py3-none-any.whl
  • Upload date:
  • Size: 56.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1025-azure

File hashes

Hashes for kabutobashi-0.8.7-py3-none-any.whl
Algorithm Hash digest
SHA256 976d719b2d57aec1c185119e10249a6358c0cc199a25a39dd6e6eb6fbac738be
MD5 5d2e56277377d157088124fc781ab56f
BLAKE2b-256 78440e7006b9436aba56ba6c4ed4246496e7066db871d255b05f43b09a9dbf35

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page