From 1e6ec919e0c692f13f9cecdaf816656e1f5d00f1 Mon Sep 17 00:00:00 2001 From: Phuoc CAO Date: Fri, 10 Feb 2023 08:59:19 +0100 Subject: [PATCH] round all calculation to 2 digits --- cao_blogr.sqlite | Bin 532480 -> 532480 bytes cao_blogr/services/portfolio.py | 9 +++-- .../templates/portfolio/portfolio.jinja2 | 4 +-- cao_blogr/views/portfolio.py | 32 +++++++++--------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cao_blogr.sqlite b/cao_blogr.sqlite index ba07d9f0a1e09bc5fce5b6ef2bd581b261897c73..bf9b8150618edcf82278b7ce324d404b892bb9be 100644 GIT binary patch delta 852 zcmX|kBbAC*nV)sp%T9#j>R16a{kx0`Fp%ih2NLZL? zzJ8P?8d8L_57L?C#Udi-H)R%K5v8bULfIsO-g}20c>cME^W5Kg&RfCCDp=VycNnkr zh=uV7SxZSSL28*gB2ul6)M!*8q1sSQ@T08cwlObSNIBWXP@C&FndmX6MdubLN1A+a zWF0IHp7uFCG8y>Ti3~APF(qZ>0-;cd_5Pq$qw@*cBU`eQP;uk$!5Y01tGArIjSovcV* zsNCL*OwouUWnYB$$+8bltlVQ(d#xQCrtC*;UNJMt4}{>o^p&X>|hhl^`9zV`^da)<5~Gx&Tqd0 zwuua3USi69uau+2B?<@)_WjvT=8BLeU}EL&-&u5d#A;XhK9?&tZejLxb!-DO`9#MV zZrH6UAYU6!{@6Z+bfYtb(-Xb>pdw5OsKJeZiA#~RFH^&mEg|px+Pt&f-s}5qcnm7R z6Fl%|CAf(UIuAk?FBgE&23wS{$NvCIs^bHpE-oTd{d7}PQ!|Q4uwDkbtlKMAc`RJ8 z8yZ8B?XAu9OnwJ6X8F$VU}`4UGY_*-CtM2f)f8JKCD$97cHIEc`+<)@l!7b#pvq=g za~mfGLY%ErE!Ed^*dM%s4o`g5x!j6N1K=C|;<|y}`3dK$pp?G#yyW#`EpC;Q zEX}n7-FxN(VW?cfC0p1rz>#z8EiOD39_j)=i8Yb|3-=@_YCSqEGJ;ZKrDJ|^)MoSg z8aUAiGP-m5=EDGITx5hWNq}>Pty>-I%BQ5>3*!v;dhs(O?4tV>TozSxMj#Rp*$~+h N*%8q_b4HRSb&W(Z~Yz%=qLBT~!V)<-JK_1SP!VV6<7#D^@ zTV#=p*ia~XMRaK{&4_B5x>H26*SBwek**E1>CDyUXZ&={>-Nlj+4lzUP%wnxOeuJ~ z3#KWW@-Zj^M3hgm7ulGD%cKw^3$^+Y$KCQ*U%NLJxruD`bMKpj=U=d?Q)bceym8HB zPtM3lNR{2|mlRH`juuI*BPrwW5{eJ|p*JvN(i7d%_}Q(oq6hhQIPP4o*P&g8KH2Su z9{5X%Bn!7wM-gue0aW3|^DkXQe? z{1WrJJw;JC1agE8SRW2G+y{SItc`+H7elO}3S#^x5*BHu^-9KSRR6~)7`-gMlg)E3^&OgOwc-Y9 z3rc%L_Qaz`2p8LX8Tv^s2)6peE+&wP?Q3ejzqDa156&`ygziZH;NSijmzzK(RtW|# vIA^mSw$2pEFvo {{ item.classe }} {{ item.pc_cible }} % - {{ '{0:0.1f}'.format(item.pc_atteint) }} + {{ '{0:0.1f}'.format(item.pc_atteint) }} % {% if (item.pc_atteint - item.pc_cible) >= 0 %} {{ '{0:0.1f}'.format(item.pc_ecart) }} {% else %} @@ -83,7 +83,7 @@
-

Mes actifs

+

Mes actifs

"Diversification is not determined by the number of securities held." Larry Swedroe

diff --git a/cao_blogr/views/portfolio.py b/cao_blogr/views/portfolio.py index 528aa0f..ccd850c 100644 --- a/cao_blogr/views/portfolio.py +++ b/cao_blogr/views/portfolio.py @@ -60,11 +60,11 @@ def portfolio(request): if symbole == 'SHLDQ': cours = 0 else: - cours = ticker.fast_info.get('lastPrice') + cours = round(ticker.fast_info.get('lastPrice'), 3) - valeur = cours * item.Actifs.parite * item.Actifs.nombre - plus_value = valeur - (item.Actifs.pru * item.Actifs.nombre) - pc_plusvalue = valeur * 100 / (item.Actifs.pru * item.Actifs.nombre) - 100 + valeur = round(cours * item.Actifs.parite * item.Actifs.nombre, 3) + plus_value = round(valeur - (item.Actifs.pru * item.Actifs.nombre),2) + pc_plusvalue = round(valeur * 100 / (item.Actifs.pru * item.Actifs.nombre) - 100, 3) PFService.update_actif_valeur(request, symbole, cours, valeur, plus_value, pc_plusvalue) # time.sleep(1) # attendre 2 secondes @@ -198,7 +198,7 @@ def histo_edit(request): # lire le cours de l'indice de réfence : Carmignac Investissement A EUR Acc ticker = yf.Ticker('0P00000FB2.F') - entry.cours_ref = ticker.fast_info.last_price + entry.cours_ref = round(ticker.fast_info.last_price, 3) # lire le dernier histo last = PFService.get_last_histo(request) @@ -211,9 +211,9 @@ def histo_edit(request): entry.valeur_pf = valeur_pf # nlle valeur part = ancienne + nouvelle ratio - entry.nb_part = last.nb_part + (float(entry.mvt_cash) / (valeur_pf - float(entry.mvt_cash))/last.nb_part) - entry.val_part = entry.valeur_pf / entry.nb_part - entry.val_part_ref = float(entry.cours_ref) * last.val_part_ref / last.cours_ref + entry.nb_part = round(last.nb_part + (float(entry.mvt_cash) / (valeur_pf - float(entry.mvt_cash))/last.nb_part), 3) + entry.val_part = round(entry.valeur_pf / entry.nb_part, 3) + entry.val_part_ref = round(float(entry.cours_ref) * last.val_part_ref / last.cours_ref, 3) request.dbsession.add(entry) @@ -272,10 +272,10 @@ def actif_edit(request): entry.libelle = entry.libelle.replace('UCITS ','') entry.libelle = entry.libelle.replace('World U','World') entry.pc_allocation = 1.0 - entry.valeur = float(entry.cours) * entry.parite * entry.nombre; - entry.plus_value = entry.valeur - float(entry.pru * entry.nombre); - entry.pc_plusvalue = entry.plus_value / entry.valeur * 100; - entry.rendement = entry.valeur * float(entry.pc_rdt) / 100; + entry.valeur = round(float(entry.cours) * entry.parite * entry.nombre, 3) + entry.plus_value = round(entry.valeur - float(entry.pru * entry.nombre), 3) + entry.pc_plusvalue = round(entry.plus_value / entry.valeur * 100, 3) + entry.rendement = 0 # round(entry.valeur * float(entry.pc_rdt) / 100, 3) request.dbsession.add(entry) return HTTPFound(location=request.route_url('portfolio')) else: @@ -289,10 +289,10 @@ def actif_edit(request): # raccourcir le libelle entry.libelle = entry.libelle.replace('UCITS ','') entry.libelle = entry.libelle.replace('World U','World') - entry.valeur = float(entry.cours) * entry.parite * entry.nombre; - entry.plus_value = entry.valeur - float(entry.pru * entry.nombre); - entry.pc_plusvalue = entry.plus_value / entry.valeur * 100; - entry.rendement = entry.valeur * float(entry.pc_rdt) / 100; + entry.valeur = round(float(entry.cours) * entry.parite * entry.nombre, 3) + entry.plus_value = round(entry.valeur - float(entry.pru * entry.nombre), 3) + entry.pc_plusvalue = round(entry.plus_value / entry.valeur * 100, 3) + entry.rendement = 0 # round(entry.valeur * float(entry.pc_rdt) / 100, 3) return HTTPFound(location=request.route_url('portfolio'))