Fwd: Ask for a question
Hi,
Would you please tell me whether PostgreSQL can execute the following
tasks? If not, please also tell me which one can help me for that. Thanks
------------------------------
*謝宗翰* *|* *台北富邦銀行* *風險管理部* *| 10686**台北市大安區仁愛路四段**169**號**12**樓**| (02)
27716699 **分機* *62853*
*Pierre Hsieh** | Taipei Fubon Bank | Risk Management Department | +886 2
27716699 ext 62853 <%2B886%202%2027716699%20ext%2062853>*
------------------------------
本郵件之資訊可能含有機密或特殊管制之資料,僅供指定之收件人使用。若台端非本郵件所指定之收件人,請立即刪除本郵件並通知寄件者。若郵件內容涉及有價證券或金融商品之資訊,其不構成要約、招攬或銷售之任何表示,亦不保證任何收益。網路通訊無法保證本郵件之安全性,若因此造成任何損害,寄件人恕不負責。This
email is intended solely for the use of the addressee and may contain
confidential and privileged information. If you have received this email in
error, please delete the email and notify the sender immediately. If any
information contained in this email involves any securities or financial
products, it shall not be construed as an offer, solicitation or sale
thereof, nor shall it guarantee any earnings. Internet communications
cannot be guaranteed to be secure or virus-free; the sender accepts no
liability for any errors or omissions.
Import Notes
Reply to msg id not found: 2A7D17935BC9D44991A9E5FC32D5655E90EFEBDD@TPEFHCMALMBS01Reference msg id not found: 2A7D17935BC9D44991A9E5FC32D5655E90EFEBDD@TPEFHCMALMBS01
On 21/01/2015 14:38, Pierre Hsieh wrote:
Hi,
Would you please tell me whether PostgreSQL can execute the following
tasks? If not, please also tell me which one can help me for that. Thanks
Not clear what you're asking, but if you just want to find the standard
deviation of a sample then that's no problem:
Hope this helps,
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
More bluntly maybe :
if you can do it in Excel,
you can do it in Postgres.
Cheers,
Rémi-C
2015-01-21 16:37 GMT+01:00 Raymond O'Donnell <rod@iol.ie>:
Show quoted text
On 21/01/2015 14:38, Pierre Hsieh wrote:
Hi,
Would you please tell me whether PostgreSQL can execute the following
tasks? If not, please also tell me which one can help me for that. ThanksNot clear what you're asking, but if you just want to find the standard
deviation of a sample then that's no problem:Hope this helps,
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
This is not quite true. I don't believe there are any flight
simulator easter-eggs hidden inside the Postgres code. :)
On Wed, Jan 21, 2015 at 10:59 AM, Rémi Cura <remi.cura@gmail.com> wrote:
More bluntly maybe :
if you can do it in Excel,
you can do it in Postgres.Cheers,
Rémi-C2015-01-21 16:37 GMT+01:00 Raymond O'Donnell <rod@iol.ie>:
On 21/01/2015 14:38, Pierre Hsieh wrote:
Hi,
Would you please tell me whether PostgreSQL can execute the following
tasks? If not, please also tell me which one can help me for that.
ThanksNot clear what you're asking, but if you just want to find the standard
deviation of a sample then that's no problem:Hope this helps,
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
On 21/01/2015 16:06, Brian Dunavant wrote:
This is not quite true. I don't believe there are any flight
simulator easter-eggs hidden inside the Postgres code. :)
No? Awww..... :-)
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Hi guys,
Thanks for your replies.
I certainly can use VBA and ADODB object in Excel to do it. Due to
performance, I wanna try to do it by SQL command in PG. However, I am not
expert in PG, so I need few help from your guys. Let me to describe my
question clearly as following.
The final results which I wanna get
are STDDEV(a1,a2,a3,...), STDDEV(b1,b2,b3,...), ..etc. I definitely know
how to use standard deviation function in PG, but the critical problem for
me is how to calculate a1, a2, a3, b1, b2, b3...etc. The rule to calculate
them is a little complicated because it needs not only moving window
function but also few logical rules. Please see details as following or
attachment. I put some colors in rules. Hopefully, it's easier for you guys
to read them. Thanks
I really need the helps from your guys. Please give me some suggestions.
Thanks.
Pierre
[image: Inline image 1]
On Thu, Jan 22, 2015 at 12:42 AM, Raymond O'Donnell <rod@iol.ie> wrote:
Show quoted text
On 21/01/2015 16:06, Brian Dunavant wrote:
This is not quite true. I don't believe there are any flight
simulator easter-eggs hidden inside the Postgres code. :)No? Awww..... :-)
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
On 21/01/2015 17:32, Pierre Hsieh wrote:
Hi guys,
Thanks for your replies.
I certainly can use VBA and ADODB object in Excel to do it. Due to
performance, I wanna try to do it by SQL command in PG. However, I am
not expert in PG, so I need few help from your guys. Let me to describe
my question clearly as following.The final results which I wanna get
are STDDEV(a1,a2,a3,...), STDDEV(b1,b2,b3,...), ..etc. I definitely know
how to use standard deviation function in PG, but the critical problem
for me is how to calculate a1, a2, a3, b1, b2, b3...etc. The rule to
calculate them is a little complicated because it needs not only moving
window function but also few logical rules. Please see details as
following or attachment. I put some colors in rules. Hopefully, it's
easier for you guys to read them. Thanks
Sorry, either I'm being stupid or your description isn't clear. Can you
show your table structure, ideally with some sample data, and what you
hope to get from the query?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Pierre
[image: Inline image 1]
On Thu, Jan 22, 2015 at 1:48 AM, Raymond O'Donnell <rod@iol.ie> wrote:
Show quoted text
On 21/01/2015 17:32, Pierre Hsieh wrote:
Hi guys,
Thanks for your replies.
I certainly can use VBA and ADODB object in Excel to do it. Due to
performance, I wanna try to do it by SQL command in PG. However, I am
not expert in PG, so I need few help from your guys. Let me to describe
my question clearly as following.The final results which I wanna get
are STDDEV(a1,a2,a3,...), STDDEV(b1,b2,b3,...), ..etc. I definitely know
how to use standard deviation function in PG, but the critical problem
for me is how to calculate a1, a2, a3, b1, b2, b3...etc. The rule to
calculate them is a little complicated because it needs not only moving
window function but also few logical rules. Please see details as
following or attachment. I put some colors in rules. Hopefully, it's
easier for you guys to read them. ThanksSorry, either I'm being stupid or your description isn't clear. Can you
show your table structure, ideally with some sample data, and what you
hope to get from the query?Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Hi Pierre,
It looks like you're saying that each row has an id plus three numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:
create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)
But if that's correct, then I think your table is badly structured for
a relational database. It might be better to have just two columns: an
id and *one* numeric value. Or perhaps an id and an array of numeric
values if you really want all values in one row.
At a higher level, if you are really taking the stddev of a sample of
size 3, you should reconsider applying statistical analysis to your
problem at all.
I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
_________________________________
Pulchritudo splendor veritatis.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
On 01/21/2015 11:02 AM, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Pierre
Inline image 1
On Thu, Jan 22, 2015 at 1:48 AM, Raymond O'Donnell <rod@iol.ie
<mailto:rod@iol.ie>> wrote:On 21/01/2015 17:32, Pierre Hsieh wrote:
Hi guys,
Thanks for your replies.
I certainly can use VBA and ADODB object in Excel to do it. Due to
performance, I wanna try to do it by SQL command in PG. However,I am
not expert in PG, so I need few help from your guys. Let me to
describe
my question clearly as following.
The final results which I wanna get
are STDDEV(a1,a2,a3,...), STDDEV(b1,b2,b3,...), ..etc. Idefinitely know
how to use standard deviation function in PG, but the critical
problem
for me is how to calculate a1, a2, a3, b1, b2, b3...etc. The rule to
calculate them is a little complicated because it needs not onlymoving
window function but also few logical rules. Please see details as
following or attachment. I put some colors in rules. Hopefully, it's
easier for you guys to read them. ThanksSorry, either I'm being stupid or your description isn't clear.
Can you
show your table structure, ideally with some sample data, and what you
hope to get from the query?Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie <mailto:rod@iol.ie>
If you have a four column table as defined in your spreadsheet, with
column names A,B,C,D
select rowsum = B - (C*A) +D;
might get you the sums you need but I don't understand the grouping of
these for the STDDEV function
Hi Pierre,
Looking at your Excel document I think I misinterpreted, and you are
trying to take the stddev of each column separately (which makes a lot
more sense!). In the case you can say this:
select id, stddev(a), stddev(b), stddev(c) from foo group by id;
Paul
On Wed, Jan 21, 2015 at 10:15 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:
Hi Pierre,
It looks like you're saying that each row has an id plus three numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)But if that's correct, then I think your table is badly structured for
a relational database. It might be better to have just two columns: an
id and *one* numeric value. Or perhaps an id and an array of numeric
values if you really want all values in one row.At a higher level, if you are really taking the stddev of a sample of
size 3, you should reconsider applying statistical analysis to your
problem at all.I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general--
_________________________________
Pulchritudo splendor veritatis.
--
_________________________________
Pulchritudo splendor veritatis.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Oh sorry, you should leave off the grouping:
select stddev(a), stddev(b), stddev(c) from foo;
Paul
On Wed, Jan 21, 2015 at 10:24 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:
Hi Pierre,
Looking at your Excel document I think I misinterpreted, and you are
trying to take the stddev of each column separately (which makes a lot
more sense!). In the case you can say this:select id, stddev(a), stddev(b), stddev(c) from foo group by id;
Paul
On Wed, Jan 21, 2015 at 10:15 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:Hi Pierre,
It looks like you're saying that each row has an id plus three numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)But if that's correct, then I think your table is badly structured for
a relational database. It might be better to have just two columns: an
id and *one* numeric value. Or perhaps an id and an array of numeric
values if you really want all values in one row.At a higher level, if you are really taking the stddev of a sample of
size 3, you should reconsider applying statistical analysis to your
problem at all.I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general--
_________________________________
Pulchritudo splendor veritatis.--
_________________________________
Pulchritudo splendor veritatis.
--
_________________________________
Pulchritudo splendor veritatis.
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Thanks for your reply.
Let me to describe the purpose for this calculation roughly.
Column B is for the price of stock.
Column C & D are the slope and interception of linear regression
from Column B.
The final result which I need is the standard deviation on the difference
between stock price and the implied price from linear regression by each
250 historical data(moving window)
Hopefully, it's clear for you to understand this calculation. Thanks
[image: Inline image 1]
On Thu, Jan 22, 2015 at 2:15 AM, Paul Jungwirth <pj@illuminatedcomputing.com
Show quoted text
wrote:
Hi Pierre,
It looks like you're saying that each row has an id plus three numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)But if that's correct, then I think your table is badly structured for
a relational database. It might be better to have just two columns: an
id and *one* numeric value. Or perhaps an id and an array of numeric
values if you really want all values in one row.At a higher level, if you are really taking the stddev of a sample of
size 3, you should reconsider applying statistical analysis to your
problem at all.I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general--
_________________________________
Pulchritudo splendor veritatis.
updated rule
[image: Inline image 1]
On Thu, Jan 22, 2015 at 2:28 AM, Pierre Hsieh <pierre.hsieh@gmail.com>
wrote:
Show quoted text
Thanks for your reply.
Let me to describe the purpose for this calculation roughly.
Column B is for the price of stock.
Column C & D are the slope and interception of linear regression
from Column B.
The final result which I need is the standard deviation on the difference
between stock price and the implied price from linear regression by each
250 historical data(moving window)Hopefully, it's clear for you to understand this calculation. Thanks
[image: Inline image 1]
On Thu, Jan 22, 2015 at 2:15 AM, Paul Jungwirth <
pj@illuminatedcomputing.com> wrote:Hi Pierre,
It looks like you're saying that each row has an id plus three numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)But if that's correct, then I think your table is badly structured for
a relational database. It might be better to have just two columns: an
id and *one* numeric value. Or perhaps an id and an array of numeric
values if you really want all values in one row.At a higher level, if you are really taking the stddev of a sample of
size 3, you should reconsider applying statistical analysis to your
problem at all.I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following. Thanks again.
Can you describe *in words* what sort of calculation you want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general--
_________________________________
Pulchritudo splendor veritatis.
On 01/21/2015 11:31 AM, Pierre Hsieh wrote:
updated rule
Inline image 1
On Thu, Jan 22, 2015 at 2:28 AM, Pierre Hsieh <pierre.hsieh@gmail.com
<mailto:pierre.hsieh@gmail.com>> wrote:Thanks for your reply.
Let me to describe the purpose for this calculation roughly.
Column B is for the price of stock.
Column C & D are the slope and interception of linear regression
from Column B.
The final result which I need is the standard deviation on the
difference between stock price and the implied price from linear
regression by each 250 historical data(moving window)Hopefully, it's clear for you to understand this calculation. Thanks
Inline image 1
On Thu, Jan 22, 2015 at 2:15 AM, Paul Jungwirth
<pj@illuminatedcomputing.com <mailto:pj@illuminatedcomputing.com>>
wrote:Hi Pierre,
It looks like you're saying that each row has an id plus three
numeric
columns, and you want the stddev calculated from the three numeric
columns? In that case you could do this:create table foo (id integer, a float, b float, c float);
insert into foo values (1, 2,3,4);
insert into foo values (2, 2,3,4);
select id, stddev(x) from (select id, unnest(array[a,b,c]) x
from foo)
bar group by id;
id | stddev
----+--------
1 | 1
2 | 1
(2 rows)But if that's correct, then I think your table is badly
structured for
a relational database. It might be better to have just two
columns: an
id and *one* numeric value. Or perhaps an id and an array of
numeric
values if you really want all values in one row.At a higher level, if you are really taking the stddev of a
sample of
size 3, you should reconsider applying statistical analysis to
your
problem at all.I hope this helps!
Paul
On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell
<rod@iol.ie <mailto:rod@iol.ie>> wrote:On 21/01/2015 18:02, Pierre Hsieh wrote:
Hi Raymond,
Thanks for your reply. Please see detail as following.
Thanks again.
Can you describe *in words* what sort of calculation you
want to do?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie <mailto:rod@iol.ie>--
Sent via pgsql-general mailing list(pgsql-general@postgresql.org
<mailto:pgsql-general@postgresql.org>)To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general--
_________________________________
Pulchritudo splendor veritatis.
You need to define a window function which captures 250 rows,
seqentially then apply the arithmetic stddev(b - (d *
(current-window-position % 250) + c)