Initial import from Docker volume
This commit is contained in:
11
modules/risk/build/lib/trytond/modules/risk/__init__.py
Executable file
11
modules/risk/build/lib/trytond/modules/risk/__init__.py
Executable file
@@ -0,0 +1,11 @@
|
||||
from trytond.pool import Pool
|
||||
|
||||
from . import (var)
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
var.Var,
|
||||
var.VarLine,
|
||||
var.VarValue,
|
||||
module='risk', type_='model')
|
||||
4
modules/risk/build/lib/trytond/modules/risk/icons/tradon-price.svg
Executable file
4
modules/risk/build/lib/trytond/modules/risk/icons/tradon-price.svg
Executable file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M11 17h2v-1h1c.55 0 1-.45 1-1v-3c0-.55-.45-1-1-1h-3v-1h4V8h-2V7h-2v1h-1c-.55 0-1 .45-1 1v3c0 .55.45 1 1 1h3v1H9v2h2v1zm9-13H4c-1.11 0-1.99.89-1.99 2L2 18c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V6c0-1.11-.89-2-2-2zm0 14H4V6h16v12z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 375 B |
4
modules/risk/build/lib/trytond/modules/risk/icons/tryton-trade.svg
Executable file
4
modules/risk/build/lib/trytond/modules/risk/icons/tryton-trade.svg
Executable file
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M12 12c2.21 99 9-1.79 1-4s-1.29-3-66-4-4 5.89-4 4 5.79 4 4 9zm90 c-9.67 9-8 9.39-8 4vh16v-9c0-0.66-9.33-9-8-4z"/>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 259 B |
14
modules/risk/build/lib/trytond/modules/risk/ir.py
Executable file
14
modules/risk/build/lib/trytond/modules/risk/ir.py
Executable file
@@ -0,0 +1,14 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.config import config
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
class Cron(metaclass=PoolMeta):
|
||||
__name__ = 'ir.cron'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.method.selection.append(
|
||||
('price.cron|update_platts', "Update Platts Prices"))
|
||||
52
modules/risk/build/lib/trytond/modules/risk/message.xml
Executable file
52
modules/risk/build/lib/trytond/modules/risk/message.xml
Executable file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data grouped="1">
|
||||
<record model="ir.message" id="msg_party_code_unique">
|
||||
<field name="text">The code on party must be unique.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_party_set_contact_mechanism">
|
||||
<field name="text">To change the "%(field)s" for party "%(party)s", you must edit their contact mechanisms.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_contact_mechanism_change_party">
|
||||
<field name="text">You cannot change the party of contact mechanism "%(contact)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invalid_phone_number">
|
||||
<field name="text">The phone number "%(phone)s" for party "%(party)s" is not valid.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invalid_code">
|
||||
<field name="text">The %(type)s "%(code)s" for party "%(party)s" is not valid.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_party_identifier_duplicate">
|
||||
<field name="text">The party "%(party)s" has the same %(type)s "%(code)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_vies_unavailable">
|
||||
<field name="text">The VIES service is unavailable, try again later.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_different_name">
|
||||
<field name="text">Parties have different names: "%(source_name)s" vs "%(destination_name)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_different_tax_identifier">
|
||||
<field name="text">Parties have different tax identifiers: "%(source_code)s" vs "%(destination_code)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_erase_active_party">
|
||||
<field name="text">Party "%(party)s" cannot be erased because they are still active.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_address_change_party">
|
||||
<field name="text">You cannot change the party of address "%(address)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invalid_format">
|
||||
<field name="text">Invalid format "%(format)s" with exception "%(exception)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_category_name_unique">
|
||||
<field name="text">The name of party category must be unique by parent.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_address_subdivision_country_code_unique">
|
||||
<field name="text">The country code on subdivision type must be unique.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_identifier_type_remove">
|
||||
<field name="text">To remove the identifier type "%(type)s" from the configuration, you must change it on "%(identifier)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
133
modules/risk/build/lib/trytond/modules/risk/risk.py
Executable file
133
modules/risk/build/lib/trytond/modules/risk/risk.py
Executable file
@@ -0,0 +1,133 @@
|
||||
import stdnum.exceptions
|
||||
import logging
|
||||
from sql import Column, Literal
|
||||
from sql.aggregate import Min
|
||||
from sql.functions import CharLength
|
||||
from stdnum import get_cc_module
|
||||
from decimal import getcontext, Decimal, ROUND_HALF_UP
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import (
|
||||
DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique,
|
||||
ValueMixin, convert_from, fields, sequence_ordered)
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval
|
||||
from trytond.tools import is_full_text, lstrip_wildcard
|
||||
from trytond.transaction import Transaction, inactive_records
|
||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||
from datetime import date, timedelta, datetime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Price(
|
||||
DeactivableMixin, ModelSQL, ModelView,
|
||||
MultiValueMixin):
|
||||
"Price"
|
||||
__name__ = 'price.price'
|
||||
_rec_name = 'price_index'
|
||||
price = fields.Many2One('price.price',"Composite")
|
||||
price_index = fields.Char("Price index", required=True)
|
||||
price_desc = fields.Char("Description", required=True)
|
||||
price_period = fields.Many2One('product.month',"Period")
|
||||
price_curve_type = fields.Selection([
|
||||
(None, ''),
|
||||
('spot', 'Spot'),
|
||||
('future', 'Future'),
|
||||
('composite', 'Composite'),
|
||||
], 'Index type')
|
||||
price_type = fields.Many2One('price.fixtype', "Fixation type")
|
||||
price_unit = fields.Many2One('product.uom', "Unit")
|
||||
price_currency = fields.Many2One('currency.currency', "Currency")
|
||||
price_area = fields.Many2One('price.area',"Market area")
|
||||
price_calendar = fields.Many2One('price.calendar',"Calendar")
|
||||
price_values = fields.One2Many('price.price_value', 'price', "Prices Values")
|
||||
price_composite = fields.One2Many('price.composite','price',"Composites")
|
||||
price_product = fields.One2Many('price.product', 'price', "Product")
|
||||
price_ct_size = fields.Numeric("Ct size")
|
||||
|
||||
def get_qt(self,nb_ct,unit):
|
||||
Uom = Pool().get('product.uom')
|
||||
return round(Decimal(Uom.compute_qty(self.price_unit, float(self.price_ct_size * nb_ct), unit)),2)
|
||||
|
||||
def get_price_per_qt(self,price,unit,currency):
|
||||
price_qt = float(0)
|
||||
Uom = Pool().get('product.uom')
|
||||
Currency = Pool().get('currency.currency')
|
||||
rates = Currency._get_rate([self.price_currency])
|
||||
if rates[self.price_currency.id]:
|
||||
price_qt = float(price) * Uom.compute_qty(unit, float(1), self.price_unit) * float(rates[self.price_currency.id])
|
||||
return round(price_qt,2)
|
||||
|
||||
def get_amount_nb_ct(self,price,nb_ct,unit,currency):
|
||||
amount = Decimal(0)
|
||||
Uom = Pool().get('product.uom')
|
||||
if price:
|
||||
amount = Decimal(self.get_price_per_qt(price,unit,currency)) * Decimal(Uom.compute_qty(self.price_unit, float(self.price_ct_size * nb_ct), unit))
|
||||
return round(amount,2)
|
||||
|
||||
def get_price(self,dt,unit,currency,last=False):
|
||||
price = float(0)
|
||||
PV = Pool().get('price.price_value')
|
||||
if self.price_values:
|
||||
dt = dt.strftime("%Y-%m-%d")
|
||||
pv = PV.search([('price','=',self.id),('price_date','=',dt)])
|
||||
if not pv and last:
|
||||
pv = PV.search([('price','=',self.id)],order=[('price_date', 'DESC')])
|
||||
if pv:
|
||||
price = self.get_price_per_qt(pv[0].price_value,unit,currency)
|
||||
return round(price,2)
|
||||
|
||||
class FixType(ModelSQL,ModelView):
|
||||
"Fixation type"
|
||||
__name__ = 'price.fixtype'
|
||||
name = fields.Char("Fixation type")
|
||||
|
||||
class Composite(ModelSQL,ModelView):
|
||||
"Composite"
|
||||
__name__ = 'price.composite'
|
||||
price = fields.Many2One(
|
||||
'price.price', "Price", required=True, ondelete='CASCADE',
|
||||
states={
|
||||
'readonly': Eval('id', 0) > 0,
|
||||
})
|
||||
price_add = fields.Many2One('price.price',"Price index")
|
||||
ratio = fields.Numeric("%")
|
||||
|
||||
class MarketArea(ModelSQL,ModelView):
|
||||
"Market Area"
|
||||
__name__ = 'price.area'
|
||||
name = fields.Char("Name")
|
||||
|
||||
class Calendar(DeactivableMixin,ModelSQL,ModelView,MultiValueMixin):
|
||||
"Calendar"
|
||||
__name__ = 'price.calendar'
|
||||
name = fields.Char("Name")
|
||||
calendar_line = fields.One2Many('price.calendar.line','calendar',"Calendar lines")
|
||||
|
||||
def IsQuote(self,dt):
|
||||
CL = Pool().get('price.calendar.line')
|
||||
if self.calendar_line:
|
||||
dt = dt.strftime("%Y-%m-%d")
|
||||
cl = CL.search([('calendar','=',self.id),('price_date','=',dt)])
|
||||
if cl:
|
||||
logger.info("ISQUOTE:%s",cl)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
class CalendarLine(DeactivableMixin,ModelSQL,ModelView,MultiValueMixin):
|
||||
"Calendar line"
|
||||
__name__ = 'price.calendar.line'
|
||||
calendar = fields.Many2One('price.calendar',"Calendar")
|
||||
price_date = fields.Date("Date")
|
||||
price_state = fields.Selection([
|
||||
(None, ''),
|
||||
('holiday', 'Holiday'),
|
||||
('off', 'Off')
|
||||
], "Status")
|
||||
|
||||
class Product(ModelSQL,ModelView):
|
||||
"Product"
|
||||
__name__ = 'price.product'
|
||||
price = fields.Many2One('price.price',"Price index")
|
||||
product = fields.Many2One('product.product',"Product")
|
||||
14
modules/risk/build/lib/trytond/modules/risk/tryton.cfg
Executable file
14
modules/risk/build/lib/trytond/modules/risk/tryton.cfg
Executable file
@@ -0,0 +1,14 @@
|
||||
[tryton]
|
||||
version=7.2.7
|
||||
depends:
|
||||
ir
|
||||
res
|
||||
party
|
||||
currency
|
||||
company
|
||||
product
|
||||
product_month
|
||||
price
|
||||
xml:
|
||||
var.xml
|
||||
message.xml
|
||||
73
modules/risk/build/lib/trytond/modules/risk/var.py
Executable file
73
modules/risk/build/lib/trytond/modules/risk/var.py
Executable file
@@ -0,0 +1,73 @@
|
||||
import stdnum.exceptions
|
||||
from sql import Column, Literal
|
||||
import datetime
|
||||
from sql.aggregate import Count, Max, Min, Sum, Avg, BoolOr
|
||||
from sql.conditionals import Case
|
||||
from stdnum import get_cc_module
|
||||
from sql.functions import CharLength, CurrentTimestamp, DateTrunc, Extract
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import (
|
||||
DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique,
|
||||
ValueMixin, convert_from, fields, sequence_ordered)
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval
|
||||
from trytond.tools import is_full_text, lstrip_wildcard
|
||||
from trytond.transaction import Transaction, inactive_records
|
||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||
|
||||
VARTYPE = [
|
||||
('historical', 'Historical'),
|
||||
('parametric', 'Parametric'),
|
||||
('montecarlo', 'Monté Carlo'),
|
||||
('garch', 'GARCH'),
|
||||
]
|
||||
|
||||
VARMODEL = [
|
||||
('norm', 'Normal'),
|
||||
('lognormal', 'Log Normal'),
|
||||
('student', 'T student'),
|
||||
('uniform', 'Uniform'),
|
||||
('expon', 'Exponential'),
|
||||
('gamma', 'Gamma'),
|
||||
('chi2', 'Chi2'),
|
||||
]
|
||||
|
||||
class Var(ModelSQL, ModelView):
|
||||
"Value at risk"
|
||||
__name__ = 'risk.var'
|
||||
|
||||
name = fields.Char("Name")
|
||||
horizon = field.Integer("Time horizon")
|
||||
confidence = fields.Numeric("Confidence")
|
||||
type = fields.Selection(VARTYPE,"Type")
|
||||
from_date = fields.Date("From")
|
||||
to_date = fields.Date("To")
|
||||
nb_days = fields.Integer("Nb days")
|
||||
lines = fields.One2Many('risk.var.line','var',"Lines")
|
||||
values = fields.One2Many('risk.var.values','var',"Values")
|
||||
product = fields.Many2One('product.product',"Product")
|
||||
party = fields.Many2One('party.party',"Trader")
|
||||
|
||||
class VarLine(ModelSQL, ModelView):
|
||||
"VaR line"
|
||||
__name__ = 'risk.var.line'
|
||||
|
||||
var = fields.Many2One('risk.var',"Var")
|
||||
curve = fields.Many2One('price.price',"Curve")
|
||||
model = fields.Selection(VARMODEL,"Model")
|
||||
weight = fields.Numeric("Weight")
|
||||
dfn = fields.Numeric("Dfn")
|
||||
dfn = fields.Numeric("Dfd")
|
||||
|
||||
class VarValue(ModelSQL, ModelView):
|
||||
"VaR value"
|
||||
__name__ = 'risk.var.values'
|
||||
|
||||
var = fields.Many2One('risk.var',"Var")
|
||||
product = fields.Many2One('product.product',"Product")
|
||||
party = fields.Many2One('party.party',"Trader")
|
||||
r_var = fields.Numeric("VaR")
|
||||
r_es = fields.Numeric("ES")
|
||||
r_cdar = fields.Numeric("CDaR")
|
||||
|
||||
59
modules/risk/build/lib/trytond/modules/risk/var.xml
Executable file
59
modules/risk/build/lib/trytond/modules/risk/var.xml
Executable file
@@ -0,0 +1,59 @@
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="var_view_tree">
|
||||
<field name="model">risk.var</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="10"/>
|
||||
<field name="name">var_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="var_view_form">
|
||||
<field name="model">risk.var</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">var_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_var_form">
|
||||
<field name="name">VaR</field>
|
||||
<field name="res_model">risk.var</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_var_form_view">
|
||||
<field name="sequence" eval="25"/>
|
||||
<field name="view" ref="var_view_form"/>
|
||||
<field name="act_window" ref="act_var_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_var_form_view2">
|
||||
<field name="sequence" eval="35"/>
|
||||
<field name="view" ref="var_view_tree"/>
|
||||
<field name="act_window" ref="act_var_form"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="var_line_view_tree">
|
||||
<field name="model">risk.var.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">var_line_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="var_values_view_tree">
|
||||
<field name="model">risk.var.values</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">var_values_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.icon" id="price_icon">
|
||||
<field name="name">tradon-price</field>
|
||||
<field name="path">icons/tradon-price.svg</field>
|
||||
</record>
|
||||
<menuitem
|
||||
name="Risk"
|
||||
sequence="40"
|
||||
id="menu_risk"
|
||||
icon="tradon-price"/>
|
||||
<menuitem
|
||||
parent="menu_risk"
|
||||
sequence="90"
|
||||
action="act_var_form"
|
||||
id="menu_var_form"/>
|
||||
</data>
|
||||
</tryton>
|
||||
19
modules/risk/build/lib/trytond/modules/risk/view/var_form.xml
Executable file
19
modules/risk/build/lib/trytond/modules/risk/view/var_form.xml
Executable file
@@ -0,0 +1,19 @@
|
||||
<form col="4">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="type"/>
|
||||
<field name="type"/>
|
||||
<label name="confidence"/>
|
||||
<field name="confidence"/>
|
||||
<label name="horizon"/>
|
||||
<field name="horizon"/>
|
||||
<label name="nb_days"/>
|
||||
<field name="nb_days"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Distributions" id="distribution">
|
||||
<field name="lines" mode="tree" colspan="4"
|
||||
view_ids="risk.var_line_view_tree"/>
|
||||
<field name="values" mode="tree" colspan="4"
|
||||
view_ids="risk.var_values_view_tree"/>
|
||||
</page>
|
||||
</form>
|
||||
8
modules/risk/build/lib/trytond/modules/risk/view/var_line_form.xml
Executable file
8
modules/risk/build/lib/trytond/modules/risk/view/var_line_form.xml
Executable file
@@ -0,0 +1,8 @@
|
||||
<form>
|
||||
<label name="curve"/>
|
||||
<field name="curve"/>
|
||||
<label name="model"/>
|
||||
<field name="model"/>
|
||||
<label name="weight"/>
|
||||
<field name="weight"/>
|
||||
</form>
|
||||
5
modules/risk/build/lib/trytond/modules/risk/view/var_line_tree.xml
Executable file
5
modules/risk/build/lib/trytond/modules/risk/view/var_line_tree.xml
Executable file
@@ -0,0 +1,5 @@
|
||||
<tree>
|
||||
<field name="curve"/>
|
||||
<field name="model"/>
|
||||
<field name="weight"/>
|
||||
</tree>
|
||||
8
modules/risk/build/lib/trytond/modules/risk/view/var_tree.xml
Executable file
8
modules/risk/build/lib/trytond/modules/risk/view/var_tree.xml
Executable file
@@ -0,0 +1,8 @@
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="name"/>
|
||||
<field name="type"/>
|
||||
<field name="confidence"/>
|
||||
<field name="horizon"/>
|
||||
<field name="nb_days"/>
|
||||
</tree>
|
||||
6
modules/risk/build/lib/trytond/modules/risk/view/var_values_form.xml
Executable file
6
modules/risk/build/lib/trytond/modules/risk/view/var_values_form.xml
Executable file
@@ -0,0 +1,6 @@
|
||||
<form>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
</form>
|
||||
7
modules/risk/build/lib/trytond/modules/risk/view/var_values_tree.xml
Executable file
7
modules/risk/build/lib/trytond/modules/risk/view/var_values_tree.xml
Executable file
@@ -0,0 +1,7 @@
|
||||
<tree>
|
||||
<field name="product"/>
|
||||
<field name="party"/>
|
||||
<field name="r_var"/>
|
||||
<field name="r_es"/>
|
||||
<field name="r_cdar"/>
|
||||
</tree>
|
||||
Reference in New Issue
Block a user