Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python program for the DCA logic

I’m working on a DCA trading project. I have some amount ‘X’ and I need to divide that ‘X’ amount to ‘Y’ parts. Each ‘Y’ part should have scale or ratio of ‘Z’. What I want output is ‘Y’ parts with divided amounts of ‘X’

X = 1000
Y = 4
Z = 2

then output will be

66.66, 133.33, 266.66, 533.33

Explanation: Each preceding number is double or 2 times (Z) of the previous number and are divided as 4 parts (Y) and their total sum is almost 1000 (X)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Example 2:

X = 1000
Y = 5 
Z = 1

Then output is

200, 200, 200, 200, 200

Explanation: Each preceding number is same or 1 times (Z) of the previous number and are divided as 5 parts (Y) and their total sum is almost 1000 (X)

Example 3:

X = 1000
Y = 6
Z = 1.5

Then output is

48.12, 72.18, 108.27, 162.4, 243.6, 365.41

Explanation: Each preceding number is almost 1.5 times (Z) of the previous number and are divided as 6 parts (Y) and their total sum is almost 1000 (X)

>Solution :

You could do:

X = 1000
Y = 4
Z = 2

n_parts = sum([Z ** i for i in range(Y)])

part_size = X / n_parts

output = [part_size * Z ** i for i in range(Y)]

print(output)

Output:

[66.66666666666667, 133.33333333333334, 266.6666666666667, 533.3333333333334]

This code finds the "part size", and then multiplies each output by this to the power of i, so the outputs consecutively are Z times bigger than the last.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading