<commit_before>"""
See LICENSE file for copyright and license details.
"""

"""
A file with financial calculations
"""

from modules.constant import * 
from decimal import Decimal

## Market definitions ##
# binb00
markets_euronext_brussels = [
    "ebr"
 ]

markets_euronext_other = [
    "ams"
    ,"etr"
    ,"epa"
    ,"other"
    ,"eli"
    ,"lse"
    ,"ise"
    ,"mil"
    ,"bma"
    ,"vse"
    ,"other"
]

markets_us = [
    "nyse"
    ,"nasdaq"
    ,"otc bb & pinksheets"
    ,"amex"
    ,"other us"
]

markets_options_euronext = [
    "options ams"
    ,"options ebr"
]

binb00_commissions = [
      {"2500":  [7.25, 9.75, 12.75, 12.75, 19.75, 29.75]}
    , {"5000":  [9.75, 9.25, 12.75, 12.75, 19.75, 29.75]}
    , {"25000": [13.75, 13.75, 16.75, 16.75, 24.75, 29.75]}
    , {"50000": [19.75, 19.75, 22.75, 22.75, 29.75, 59.75]}
    , {"50000+":[19.75, 19.75, 19.75, 19.72, 29.75, 29.75]}
    #TODO: expand for options?
]

# whsi00
markets_cfd_share = [
    "cfd BE"
    ,"cfd FR"
    ,"cfd DE"
    ,"cfd UK"
    ,"cfd DK"
    ,"cfd FI"
    ,"cfd IT"
    ,"cfd NL"
    ,"cfd NO"
    ,"cfd PT"
    ,"cfd SE"
    ,"cfd CH"
    ,"cfd ES"
    ,"cfd other share"
]

markets_cfd_dev1 = [
    "cfd AU"
    ,"cfd AT"
]

markets_cfd_dev2 = [
    "cfd PL"
    ,"cfd CN"
    ,"cfd SG"
]

markets_cfd_non_share = [
    "cfd .gold"
    ,"cfd .silver"
    ,"cfd oil"
    ,"cfd index"
    ,"cfd other non-share"
]

markets_cfd_us = [
    "cfd US"
]

markets = markets_euronext_brussels + markets_euronext_other + markets_us + markets_options_euronext + markets_cfd_dev1 + markets_cfd_dev2 + markets_cfd_non_share + markets_cfd_us

## Helper functions ##
def is_euronext_brussels(market):
    """
        Market elem of markets_euronext_brussels?
    """
    return market in markets_euronext_brussels

def is_euronext_other(market):
    """
        Market elem of markets_euronext_other?
    """
    return market in markets_euronext_other

def is_us(market):
    """
        Market elem of markets_us?
    """
    return market in markets_us

def is_euro_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_canada_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_swiss_scandinavian_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_non_share_cfd(market):
    """
        Market elem markets_cfd_non_share?
    """
    return market in markets_cfd_non_share

def is_share_cfd(market):
    """
        Market elem markets_cfd_share?
    """
    return market in markets_cfd_share

def is_share_cfd_dev1(market):
    """
        Market elem markets_cfd_dev1?
    """
    return market in markets_cfd_dev1

def is_share_cfd_dev2(market):
    """
        Market elem markets_cfd_dev2?
    """
    return market in markets_cfd_dev2

def is_share_cfd_us(market):
    """
        Market elem markets_cfd_us?
    """
    return market in markets_cfd_us

def is_options_euronext(market):
    """
        Market elem markets_options_euronext?
    """
    return market in markets_options_euronext

def calculate_percentage_of(value, from_value):
    """
       Calculate what percentage value is from from_value.
    """
    return value / from_value * Decimal(100.0)

## Financial calculations ##
def calculate_stoploss(price_buy, shares_buy, tax_buy, commission_buy, i_risk, pool_at_start):
    """
        Calculates the stoploss.
    """
    var_T = ((i_risk * price_buy) - calculate_amount_simple(price_buy, shares_buy)) - commission_buy
    var_N = shares_buy * (tax_buy - (1.0))
    return  var_T / var_N
        
def calculate_risk_input(i_pool, i_risk):
    """<commit_msg>Correction.<commit_after>"""
See LICENSE file for copyright and license details.
"""

"""
A file with financial calculations
"""

from modules.constant import * 
from decimal import Decimal

## Market definitions ##
# binb00
markets_euronext_brussels = [
    "ebr"
 ]

markets_euronext_other = [
    "ams"
    ,"etr"
    ,"epa"
    ,"other"
    ,"eli"
    ,"lse"
    ,"ise"
    ,"mil"
    ,"bma"
    ,"vse"
    ,"other"
]

markets_us = [
    "nyse"
    ,"nasdaq"
    ,"otc bb & pinksheets"
    ,"amex"
    ,"other us"
]

markets_options_euronext = [
    "options ams"
    ,"options ebr"
]

binb00_commissions = [
      {"2500":  [7.25, 9.75, 12.75, 12.75, 19.75, 29.75]}
    , {"5000":  [9.75, 9.25, 12.75, 12.75, 19.75, 29.75]}
    , {"25000": [13.75, 13.75, 16.75, 16.75, 24.75, 29.75]}
    , {"50000": [19.75, 19.75, 22.75, 22.75, 29.75, 59.75]}
    , {"50000+":[19.75, 19.75, 19.75, 19.72, 29.75, 29.75]}
    #TODO: expand for options?
]

# whsi00
markets_cfd_share = [
    "cfd BE"
    ,"cfd FR"
    ,"cfd DE"
    ,"cfd UK"
    ,"cfd DK"
    ,"cfd FI"
    ,"cfd IT"
    ,"cfd NL"
    ,"cfd NO"
    ,"cfd PT"
    ,"cfd SE"
    ,"cfd CH"
    ,"cfd ES"
    ,"cfd other share"
]

markets_cfd_dev1 = [
    "cfd AU"
    ,"cfd AT"
]

markets_cfd_dev2 = [
    "cfd PL"
    ,"cfd CN"
    ,"cfd SG"
]

markets_cfd_non_share = [
    "cfd .gold"
    ,"cfd .silver"
    ,"cfd oil"
    ,"cfd index"
    ,"cfd other non-share"
]

markets_cfd_us = [
    "cfd US"
]

markets = markets_euronext_brussels + markets_euronext_other + markets_us + markets_options_euronext + markets_cfd_dev1 + markets_cfd_dev2 + markets_cfd_non_share + markets_cfd_us

## Helper functions ##
def is_euronext_brussels(market):
    """
        Market elem of markets_euronext_brussels?
    """
    return market in markets_euronext_brussels

def is_euronext_other(market):
    """
        Market elem of markets_euronext_other?
    """
    return market in markets_euronext_other

def is_us(market):
    """
        Market elem of markets_us?
    """
    return market in markets_us

def is_euro_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_canada_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_swiss_scandinavian_exchange(market):
    """
        Market elem of <TBD>?
    """
    return market == "dummy"

def is_non_share_cfd(market):
    """
        Market elem markets_cfd_non_share?
    """
    return market in markets_cfd_non_share

def is_share_cfd(market):
    """
        Market elem markets_cfd_share?
    """
    return market in markets_cfd_share

def is_share_cfd_dev1(market):
    """
        Market elem markets_cfd_dev1?
    """
    return market in markets_cfd_dev1

def is_share_cfd_dev2(market):
    """
        Market elem markets_cfd_dev2?
    """
    return market in markets_cfd_dev2

def is_share_cfd_us(market):
    """
        Market elem markets_cfd_us?
    """
    return market in markets_cfd_us

def is_options_euronext(market):
    """
        Market elem markets_options_euronext?
    """
    return market in markets_options_euronext

def calculate_percentage_of(value, from_value):
    """
       Calculate what percentage value is from from_value.
    """
    return value / from_value * Decimal(100.0)

## Financial calculations ##
def calculate_stoploss(price_buy, shares_buy, tax_buy, commission_buy, i_risk, pool_at_start):
    """
        Calculates the stoploss.
    """
    var_T = ((i_risk * price_buy) - calculate_amount_simple(price_buy, shares_buy)) - commission_buy
    var_N = shares_buy * (tax_buy - Decimal(1.0))
    return  var_T / var_N
        
def calculate_risk_input(i_pool, i_risk):
    """
{'fraction_non_alphanumeric': 0.13207040171973666, 'fraction_numerical': 0.0432621254870348, 'mean_word_length': 2.7672064777327936, 'pattern_counts': {'":': 10, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '619808', 'n_tokens_mistral': 3098, 'n_tokens_neox': 2825, 'n_words': 626}